﻿using Microsoft.Extensions.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace Hhmocon.Mes.DataBase.SqlServer
{
    /// <summary>
    /// SqlServer数据库帮助类
    /// </summary>
    public class SqlServerDbHelper
    {
        /// <summary>
        /// 获取数据库上下文
        /// </summary>
        /// <returns></returns>
        public static IDbConnection GetConn()
        {
            string sqlserverconn= ConfigurationManager.Configuration.GetConnectionString("sqlserverconn");
            return new SqlConnection(sqlserverconn);
        }
    }



    public class ConfigurationManager
    {
        public readonly static IConfiguration Configuration;
        static ConfigurationManager()
        {
            Configuration = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: true,reloadOnChange:true)
            .Build();
        }
    }
}
